package com.hyxf.controller;

import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Auther:阿紫
 * @Date:2025-5-31
 * @Description:
 * @VERSON:1.8
 */
@RestController
@RequestMapping("/ai")
@CrossOrigin(origins = "*") // 允许所有来源的请求
public class DeepSeekController {
    private final DashScopeChatModel chatModel;

    public DeepSeekController(DashScopeChatModel chatModel) {
        this.chatModel = chatModel;
    }

    @GetMapping("/a1/{prompt}")
    public Generation chat(@PathVariable(value = "prompt") String prompt) {

        ChatResponse chatResponse = chatModel.call(new Prompt(prompt));

        return chatResponse.getResult();
    }

    @GetMapping("/a2/{prompt}")
    public String chatDel(@PathVariable(value = "prompt") String prompt) {

        ChatResponse chatResponse = chatModel.call(new Prompt(prompt));

        if (!chatResponse.getResults().isEmpty()) {
            Map<String, Object> metadata = chatResponse.getResults()
                    .get(0)
                    .getOutput()
                    .getMetadata();

            System.out.println(metadata.get("reasoningContent"));
        }

        return chatResponse.getResult().getOutput().getText();
    }
}
